package com.ruoyi.parking.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.parking.domain.ParkCar;
import com.ruoyi.parking.service.IParkCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆信息Controller
 * 
 * @author chenkai
 * @date 2025-02-12
 */
@RestController
@RequestMapping("/parking/car")
public class ParkCarController extends BaseController
{
    @Autowired
    private IParkCarService parkCarService;

    /**
     * 查询车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('parking:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkCar parkCar)
    {
        startPage();
        List<ParkCar> list = parkCarService.selectParkCarList(parkCar);
        return getDataTable(list);
    }

    /**
     * 导出车辆信息列表
     */
    @PreAuthorize("@ss.hasPermi('parking:car:export')")
    @Log(title = "车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkCar parkCar)
    {
        List<ParkCar> list = parkCarService.selectParkCarList(parkCar);
        ExcelUtil<ParkCar> util = new ExcelUtil<ParkCar>(ParkCar.class);
        util.exportExcel(response, list, "车辆信息数据");
    }

    /**
     * 获取车辆信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:car:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Integer carId)
    {
        return success(parkCarService.selectParkCarByCarId(carId));
    }

    /**
     * 新增车辆信息
     */
    @PreAuthorize("@ss.hasPermi('parking:car:add')")
    @Log(title = "车辆信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkCar parkCar)
    {
        return toAjax(parkCarService.insertParkCar(parkCar));
    }

    /**
     * 修改车辆信息
     */
    @PreAuthorize("@ss.hasPermi('parking:car:edit')")
    @Log(title = "车辆信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkCar parkCar)
    {
        return toAjax(parkCarService.updateParkCar(parkCar));
    }

    /**
     * 删除车辆信息
     */
    @PreAuthorize("@ss.hasPermi('parking:car:remove')")
    @Log(title = "车辆信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carIds}")
    public AjaxResult remove(@PathVariable Integer[] carIds)
    {
        return toAjax(parkCarService.deleteParkCarByCarIds(carIds));
    }
}
